#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
typedef pair<int, int> pii;
vector<int> G[maxn];
int N, T, s, f[maxn], d[maxn], maxd;

void dfs(int u, int fa){
    f[u] = fa;
    for(auto v:G[u]) if(v!=fa) d[v] = d[u]+1, maxd = max(d[v], maxd), dfs(v, u);
}

int bfs(){
    queue<pii> q;
    q.push({s, 0});
    int ans = 0;
    while (!q.empty()){
        int u = q.front().first;
        int c = q.front().second;
        q.pop();

        ans = max(ans, (d[u]+1)/2);
        if(c == (d[u]+1)/2) continue;

        for(auto v:G[u]){
            if(v != f[u]){
                q.push({v, c+1});
            }
        }
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    cin >> N >> T;
    for (int i = 0; i < N - 1; ++i) {
        int a, b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(N, N);
    s = 1;
    for (int i = 0; i < T; ++i) {
        s = f[s];
    }
    cout << min(bfs(), (maxd+1)/2);
    return 0;
}